<template>
  <div class='content'>
    <div class="profile_page">
      <head-top :go-back='goBack' :head-title="profiletitle"></head-top>
    </div>
      <div style="height: 100%">
          <iframe :src="pdfSrc"></iframe>
      </div>
  </div>
</template>

<script>
  var that;
  let Base64 = require('js-base64').Base64
  import headTop from '@/components/header/head'
  import pdf from 'vue-pdf'  // 引入pdf组件
  import CMapReaderFactory from 'vue-pdf/src/CMapReaderFactory'
  import titlebar from '@/components/titlebar3/titlebar3';
  import {getGoAbroadData,submitApply,getAttachment} from '@/service/getData';
  import {setStore,getStore,getDefault,contextRoot} from '@/assets/config/mUtils';
  import {Dialog, Toast} from 'vant';
  import {getUser} from '@/service/getData';

  export default {
    data() {
      return {
        company: "",//所属公司
        profiletitle: 'pdf预览',
        goBack: true,
        titleLeft: '基本信息',
        titleLeft1: '人员出国境信息',
        titleLeft2: '附件信息',
        id: '',
        pdfSrc: '', // pdf文件地址
        currentPage: 0, // pdf文件页码
        pageCount: 0, // pdf文件总页数
          numPages: []
      }
    },
    created() {
      that = this;
        let fileId = this.$route.query.fileId;
        let baseUrl = contextRoot();
        let checkTime = new Date().getTime().toString();
//        let url = baseUrl + "/api/file/att/download?fileId=" + fileId.base64Encode()+'&app_userId='+getStore('user_id');
        let url = baseUrl + "/mvc/appSelf/viewPdf?app_userId="+getStore('user_id')+'&fileid='+fileId.base64Encode();
        //let url =  "../../../../static/11.pdf";
        url = encodeURIComponent(url);
        this.pdfSrc = '../../../../static/pdf/pdfjs/web/viewer.html?file=' + url   //  根据自己的文件地址将viewe.html引进来
      // this.getProtocol();
    },
    mounted() {
//        var pdfSrc1 = "";
//        this.pdfSrc = pdf.createLoadingTask({ url: this.pdfSrc1, CMapReaderFactory })
    },
    components: {
      headTop,
      titlebar,
      pdf
    },
    updated() {
      let that = this;
    },
    methods: {
        getProtocol() {
            let fileId = this.$route.query.fileId;
            let baseUrl = contextRoot();
            let checkTime = new Date().getTime().toString();
//            let url = baseUrl + "/api/file/att/download?fileId=" + fileId.base64Encode()+'&app_userId='+getStore('user_id');
            let url = baseUrl + "/mvc/appSelf/download?fileId=" + fileId.base64Encode()+'&app_userId='+getStore('user_id');
            this.pdfSrc = pdf.createLoadingTask(url);
             console.log('pdfSrc', this.pdfSrc)
            // this.pdfSrc.then(pdf => { // 此行为错误示例, 报错this.pdfSrc.then is not a function
            this.pdfSrc.promise.then(pdf => {
                // console.log('pdf', pdf)
                this.numPages = pdf.numPages
            })
        }
    }
  }

</script>
<style lang="scss"  sceped>
    @import '../../assets/style/mixin';
    @import '../../assets/style/public';
    iframe{
        width: 100vw;
        height: 100vh;
        border: none;
    }
</style>
